import { createRouter, createWebHistory } from 'vue-router';
import LoginView from '../views/LoginView.vue';
import Register from '../views/Register.vue';
import HomeView from '../views/HomeView.vue';

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'Login',
    component: LoginView
  },
  {
    path: '/register',
    name: 'Register',
    component: Register
  },
  {
    path: '/home', // 把根路径改为 /home 避免冲突
    name: 'Home',
    component: HomeView,
    redirect: '/user',
    children: [
      { path: '/user', component: () => import('../views/user/UserView.vue') },
      { path: '/vehicle', component: () => import('@/views/Engineer/EngineerView.vue') },
      { path: '/geofence', component: () => import('../views/geofence/GeofenceView.vue') },
      { path: '/geofenceMap', component: () => import('../views/geofence/GeofenceMapView.vue') },
      { path: '/application', component: () => import('../views/schedule/ApplicationView.vue') },
      { path: '/audit', component: () => import('../views/schedule/AuditView.vue') },
      { path: '/distribute', component: () => import('../views/schedule/DistributeView.vue') },
      { path: '/dict', component: () => import('../views/dictionary/DictView.vue') },
      { path: '/dictOption', component: () => import('../views/dictionary/DictOptionView.vue') }
    ]
  }
];

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
});

export default router;